package com.example.q_kang.hhh.order.match;

import com.example.q_kang.hhh.api.JsonCallBack;
import com.hjq.toast.ToastUtils;
import com.lzy.okgo.model.Response;
import com.lzy.okgo.request.base.Request;
import com.sskj.base.BasePresenter;
import com.example.q_kang.hhh.order.match.SellConfirmActivity;
import com.sskj.base.api.Constant;
import com.sskj.base.base.HttpData;
import com.sskj.base.bean.SellDetailBean;


/**
 * @author Hey
 * Create at  2019/04/13
 */
class SellConfirmPresenter extends BasePresenter<SellConfirmActivity> {

    public void getOrderDetail(String order) {
        httpService.getOrderDetail(order)
                .tag(this)
                .execute(new JsonCallBack<HttpData<SellDetailBean>>() {
                    @Override
                    public void onSuccess(Response<HttpData<SellDetailBean>> response) {
                        HttpData<SellDetailBean> body = response.body();
                        if (body.getStatus() == Constant.OK) {
                            mView.getDataSuccess(body.getData());
                        } else {
                            ToastUtils.show(body.getMsg());
                        }
                    }

                    @Override
                    public void onStart(Request<HttpData<SellDetailBean>, ? extends Request> request) {
                        super.onStart(request);
                        mView.showLoading();
                    }

                    @Override
                    public void onFinish() {
                        super.onFinish();
                        mView.hideLoading();
                    }
                });
    }

    public void leaveMsg(String toUserId, String content) {
        httpService.sellLeaveMsg(toUserId, content)
                .tag(this)
                .execute(new JsonCallBack<HttpData>() {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData body = response.body();
                        ToastUtils.show(body.getMsg());
                        if (body.getStatus() == Constant.OK) {
                            mView.leaveSuccess();
                        }
                    }

                    @Override
                    public void onStart(Request<HttpData, ? extends Request> request) {
                        super.onStart(request);
                        mView.showLoading();
                    }

                    @Override
                    public void onFinish() {
                        super.onFinish();
                        mView.hideLoading();
                    }
                });

    }


    public void confirmShowQian(String order) {
        httpService.confirmShowQian(order)
                .tag(this)
                .execute(new JsonCallBack<HttpData>() {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData body = response.body();
                        ToastUtils.show(body.getMsg());
                        if (body.getStatus() == Constant.OK) {
                            mView.finish();
                        }
                    }

                    @Override
                    public void onStart(Request<HttpData, ? extends Request> request) {
                        super.onStart(request);
                        mView.showLoading();
                    }

                    @Override
                    public void onFinish() {
                        super.onFinish();
                        mView.hideLoading();
                    }
                });
    }
}
